package com.qf.sessions;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "getValueServlet",value = "/getValue")
public class getValueServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        1.通过 request 对象获取 Session 对象
        HttpSession session = request.getSession();
//        2. 获取数据
        String password  = (String) request.getAttribute("password");
        String s  = (String) session.getAttribute("username");

        System.out.println("从 session 中获取到：" + s);
        System.out.println("从 request 中获取到：" + password);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
